home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Lose Your Marbles! 1.0 / source / Shell ƒ / about.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.8 KB  |  188 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        about.c
  4.  
  5. Purpose:    This module handles displaying the about box.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "about.h"
  25. #include "prefs.h"
  26. #include "util.h"
  27.  
  28. /*-----------------------------------------------------------------------------------*/
  29. /* internal stuff for about.c                                                        */
  30.  
  31. void SetupTheAboutBox(WindowDataHandle theData);
  32. void InitializeTheAboutBox(WindowDataHandle theData);
  33. void OpenTheAboutBox(WindowDataHandle theData);
  34. void ResizeTheAboutBox(WindowDataHandle theData);
  35. void ShutdownTheAboutBox(WindowDataHandle theData);
  36. void DrawTheAboutBox(Boolean isColor);
  37. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  38. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter);
  39.  
  40. Boolean            gUseAlternate;
  41.  
  42. enum
  43. {
  44.     kAboutColorID=134
  45. };
  46.  
  47. short AboutBoxDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  48. {
  49.     short            theDepth;
  50.     
  51.     switch (theMessage)    /* see graphics.h for list of messages*/
  52.     {
  53.         case kKeydown:                            /* close about box on keypress */
  54.         case kMousedown:                        /* or mouseclick */
  55.             CloseTheWindow((ExtendedWindowDataHandle)theData);
  56.             return kSuccess;
  57.             break;
  58.         case kUpdate:
  59.             theDepth=misc&0x7fff;                /* pixel depth */
  60.             DrawTheAboutBox((theDepth>2));        /* we only care if it's color or not */
  61.             return kSuccess;
  62.             break;
  63.         case kInitialize:
  64.             InitializeTheAboutBox(theData);
  65.             return kFailure;
  66.         case kOpen:
  67.             OpenTheAboutBox(theData);
  68.             return kSuccess;
  69.             break;
  70.         case kStartup:
  71.             SetupTheAboutBox(theData);
  72.             return kSuccess;
  73.             break;
  74.         case kShutdown:
  75.             ShutdownTheAboutBox(theData);
  76.             return kSuccess;
  77.             break;
  78.     }
  79.     
  80.     return kFailure;        /* for all other messages, defer to default processing */
  81. }
  82.  
  83. void SetupTheAboutBox(WindowDataHandle theData)
  84. {
  85.     unsigned char    *theTitle="\pAbout";
  86.     
  87.     (**theData).windowType=noGrowDocProc;    /* plain vanilla window */
  88.     Mymemcpy((Ptr)((**theData).windowTitle), (Ptr)theTitle, theTitle[0]+1);
  89.     (**theData).hasCloseBox=TRUE;
  90.     (**theData).maxDepth=1;
  91.     gUseAlternate=FALSE;
  92. }
  93.  
  94. void InitializeTheAboutBox(WindowDataHandle theData)
  95. {
  96.     (**theData).windowWidth=170;
  97.     (**theData).windowHeight=216;
  98. }
  99.  
  100. void OpenTheAboutBox(WindowDataHandle theData)
  101. {
  102.     KeyMap            rawKeys;
  103.     unsigned short    theKeys[8];
  104.     
  105.     GetKeys(rawKeys);
  106.     Mymemcpy((Ptr)theKeys, (Ptr)rawKeys, sizeof(rawKeys));
  107.     if (theKeys[3]&4)    /* option key down? */
  108.     {
  109.         if (!gUseAlternate)
  110.         {
  111.             gUseAlternate=TRUE;
  112.             (**theData).offscreenNeedsUpdate=TRUE;
  113.         }
  114.     }
  115.     else
  116.     {
  117.         if (gUseAlternate)
  118.         {
  119.             gUseAlternate=FALSE;
  120.             (**theData).offscreenNeedsUpdate=TRUE;
  121.         }
  122.     }
  123. }
  124.  
  125. void ShutdownTheAboutBox(WindowDataHandle theData)
  126. {
  127. }
  128.  
  129. void DrawTheAboutBox(Boolean isColor)
  130. {
  131.     RGBColor        oldForeColor, oldBackColor;
  132.     short            row;
  133.     Handle            textHandle;
  134.     Str255            theLine;
  135.     unsigned long    pos;
  136.     unsigned long    theSize;
  137.     GrafPtr            curPort;
  138.     short            theCenter;
  139.     RGBColor        myGray={49152, 49152, 49152};
  140.     
  141.     GetPort(&curPort);
  142.     FillRect(&(curPort->portRect), black);
  143.     TextMode(srcXor);
  144.     
  145.     theCenter=(curPort->portRect.right-curPort->portRect.left)/2;
  146.     
  147.     TextFont(geneva);
  148.     TextSize(9);
  149.     row=16;
  150.     textHandle=GetResource('TEXT', gUseAlternate ? 129 : 128);
  151.     if (textHandle==0L)
  152.         return;
  153.     if (*textHandle==0L)
  154.         LoadResource(textHandle);
  155.     if (*textHandle==0L)
  156.         return;
  157.     pos=0L;
  158.     theSize=SizeResource(textHandle);
  159.     do
  160.     {
  161.         GetTheNextLine(textHandle, theSize, &pos, theLine);
  162.         DrawTheAboutString(theLine, &row, theCenter);
  163.     }
  164.     while (pos<theSize);
  165.     ReleaseResource(textHandle);
  166.     DrawTheAboutString(gMyName, &row, theCenter);
  167.     DrawTheAboutString(gMyOrg, &row, theCenter);
  168.     TextMode(srcCopy);
  169.     TextSize(12);
  170.     TextFont(0);
  171. }
  172.  
  173. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine)
  174. {
  175.     unsigned char    theChar;
  176.     
  177.     theLine[0]=0x00;
  178.     while ((*pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+((*pos)++))))!=0x0d))
  179.         theLine[++theLine[0]]=theChar;
  180. }
  181.  
  182. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter)
  183. {
  184.     MoveTo(theCenter-StringWidth(theString)/2, *theRow);
  185.     DrawString(theString);
  186.     *theRow+=12;
  187. }
  188.